﻿using System;
using System.Collections.Generic;
using System.Text;
using KSWSClient.Code.IService;
using KSWSClient.Code.Model;
using KSWSClient.Code.Util;

namespace KSWSClient.Code.Service
{
    public class ConfigService : IConfigService
    {
        public ConfigModel GetConfig()
        {
            ConfigModel config = new ConfigModel();
            config.ServerHost = ClientUtil.GetNodeValue(ClientUtil.XPATH_SERVER_HOST);
            config.ServerPort = ClientUtil.GetNodeValue(ClientUtil.XPATH_SERVER_PORT);
            config.ContextPath = ClientUtil.GetNodeValue(ClientUtil.XPATH_CONTEXT_PATH);
            config.UserName = ClientUtil.GetNodeValue(ClientUtil.XPATH_USER_NAME);
            config.Password = ClientUtil.GetNodeValue(ClientUtil.XPATH_PASSWORD);
            return config;
        }

        public bool SaveConfig(ConfigModel config)
        {
            return ClientUtil.WriteConfig(
                config.ServerHost,
                config.ServerPort,
                config.ContextPath,
                config.UserName,
                config.Password);
        }
    }
}
